package com.chinasofti.emp.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.chinasofti.manager.service.EmpLeaveService;
import com.chinasofti.model.TypeOfLeave;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * Creator: <br>
 * Date: <br>
 * Description: <br>
 */
@Controller
@RequestMapping("/emp/leave")
public class EmpLeaveController {
    @Reference
    private EmpLeaveService empLeaveService;

    @GetMapping("/add")
    public ModelAndView add(){
        ModelAndView mv = new ModelAndView("leave/add");
        List<TypeOfLeave> typeOfLeaves = empLeaveService.queryTypeList();
        mv.addObject("types", typeOfLeaves);
        return mv;
    }

    @PostMapping("/add")
    public ModelAndView add(String name, String type,
                              String reason,
                              String start, String end){
        ModelAndView mv = new ModelAndView("leave/add");
        empLeaveService.leave(name, type, reason, start, end);
        mv.addObject("msg", "已提交申请");
        return mv;
    }

}
